<template>
  <div>
    <!-- 头部组件 -->
    <NavBar leftText="返回"></NavBar>
    <div class="addWrap">
      <!-- 输入框 -->
      <van-field v-model="goods" placeholder="请输入商品名称" />
      <!-- 添加按钮 -->
      <van-button type="info" size="large" @click="addGoods()">添加商品</van-button>
    </div>
    <!-- 底部tab栏  -->
    <TabBar></TabBar>
  </div>
</template>

<script>
import NavBar from "../components/navBar";
import TabBar from "../components/Tabbar";
export default {
  components: {
    NavBar,
    TabBar
  },
  data() {
    return {
      // 商品名称
      goods: ""
    };
  },
  created() {},
  methods: {
    // 添加商品
    async addGoods() {
      const { data: res } = await this.$http.post("/api/addproduct", {
        name: this.goods
      });
      if (res.status !== 0) {
        //如果状态码不为0，表示出错了
        this.$toast("添加商品失败");
        return;
      }
      // 显示提交成功
      this.$notify({ type: "success", message: "添加成功" });
      // 返回搜索页面
      this.$router.go(-1);
    }
  }
};
</script>

<style lang="less" scoped>
.addWrap {
  padding: 0 10px;
}
.van-cell {
  margin-bottom: 30px;
}
.van-button--large {
  height: 40px;
  line-height: 40px;
}
</style>